package com.prs.crm.action.personalset;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.personalset.UrlCollection;
import com.prs.crm.service.personalSet.UrlCollectionService;

public class UrlCollectionAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private UrlCollection urlCollection;
	private UrlCollectionService urlCollectionService;
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public UrlCollection getUrlCollection() {
		return urlCollection;
	}
	public void setUrlCollection(UrlCollection urlCollection) {
		this.urlCollection = urlCollection;
	}
	public UrlCollectionService getUrlCollectionService() {
		return urlCollectionService;
	}
	public void setUrlCollectionService(UrlCollectionService urlCollectionService) {
		this.urlCollectionService = urlCollectionService;
	}
	
	@Action("listUrlCollection")
	public String listUrlCollection(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(UrlCollection.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getUrlCollectionService().listByPage(criteria, pagination));
		return SUCCESS;
	} 
	
	@Action("editUrlCollection")
	public String editUrlCollection(){
		if(ids!=null){
			this.urlCollection=this.getUrlCollectionService().get(ids[0]);
		}
		return SUCCESS;
	}
	@Action(value="saveUrlCollection", results={
			@Result(name="success",type="redirect",location="listUrlCollection"),
			@Result(name="error",type="chain",location="editUrlCollection")
	})
	public String saveUrlCollection(){
		this.getUrlCollectionService().save(urlCollection);
		if (urlCollection.getName()==null||"".equals(urlCollection.getName().trim())) {
			urlCollection.setName(urlCollection.getUrl());
		}
		this.getUrlCollectionService().submit(urlCollection);
		return SUCCESS;
	}
	@Action(value="saveUrlCollections", results={
			@Result(name="success",type="redirect",location="editUrlCollection"),
			@Result(name="error",type="chain",location="editUrlCollection")
	})
	public String saveUrlCollections(){
		this.getUrlCollectionService().save(urlCollection);
		if (urlCollection.getName()==null||"".equals(urlCollection.getName().trim())) {
			urlCollection.setName(urlCollection.getUrl());
		}
		this.getUrlCollectionService().submit(urlCollection);
		return SUCCESS;
	}
	@Action(value="removeUrlCollection", results={
			@Result(name="success",type="redirect",location="listUrlCollection"),
			@Result(name="error",type="chain",location="listUrlCollection")
	})
	public String removeUrlCollection(){
		if(ids!=null){
			this.urlCollection=this.getUrlCollectionService().get(ids[0]);
		}
		this.getUrlCollectionService().batchRemove(ids);
		return SUCCESS;
	}
}
